cc.Class({
    extends: cc.Component,

    properties: {
        king:{
            default:null,
            type:cc.Node,
        },

        button_down:cc.Node,//下蹲按钮
        button_jump:cc.Node,//跳起按钮

        main_ProgressBar:cc.Node,//飞行进度条

        live:cc.Label,//生命值显示lable


    },

    onLoad: function () {
        var self = this;

        //显示生命值
        self.live.string = "生命值 " + self_live;
        
        this.button_down.on('touchend',function(event){
            
            self.king.getComponent('King').downRelease();//获取角色蹲下恢复函数
            
        });

        this.button_down.on('touchstart',function(event){
            
            self.king.getComponent('King').down();//获取角色蹲下函数
            
        });




        this.button_jump.on('touchstart',function(event){


                self.king.getComponent('player_control').onDown();//角色跳跃函数
      
        });


        this.button_jump.on('touchend',function(event){


            self.king.getComponent('player_control').onUp();
  
    });



        //打开碰撞检测
        cc.director.getCollisionManager().enabled = true;
        cc.director.getCollisionManager().enabledDebugDraw = true;

        //打开物理碰撞检测
        cc.director.getPhysicsManager().enabled = true;
        cc.director.getPhysicsManager().debugDrawFlags = cc.PhysicsManager.DrawBits.e_aabbBit;




        //测试进度条
        this.schedule(function () {
           var self = this
            self.main_ProgressBar.getComponent(cc.ProgressBar).progress += 0.01; 
            console.log(self.main_ProgressBar.getComponent(cc.ProgressBar).progress )
           if (self.main_ProgressBar.getComponent(cc.ProgressBar).progress >= 1) {
            
            if (self.king.getComponent('King').state = "run") {
                 self.king.getComponent('King').sprintProp();  
                 self.main_ProgressBar.getComponent(cc.ProgressBar).progress = 0; 
                 }
           }
        },1)

        //restart
        self.restart_unm();



    },

    //跳
    btn_jump(){

    },

    //下滑
    btn_down(){

    },



    //重新开始每一项数值
    restart_unm:function () {
        
    
    window.FloorBlockMin = 0;//中间地板块
    window.FloorBlockRight = 1;//右边地板块
    window.FloorBlockLeft = 2;//左边地板块
    window.FloorBlockNode = 3;//空地板块


    window.bg_speed = 5;

    window.self_live = 1;//设置生命值

    },



    //结束游戏
    OverGame:function () {
    cc.director.loadScene('Over');//加载结束场景
    },


    update(){
        this.live.string = "生命值 " + self_live;//更新角色生命值
    },

});
